import Vue from 'vue'
import Router from 'vue-router';

Vue.use(Router)

const constantRoutes = [
    {
      path: "/login", //登录
      name: "login",
      hidden: true,
      component: () => import('@/views/Login/Login')
    },
    {
      path: "/404", //404
      name: "error",
      hidden: true,
      component: () => import('@/views/Notfound/404')
    },
    {
      path: '/',
      name: 'index',
      redirect: '/home',
      component: () => import('@/components/index'),
      hidden: true,
      children: [
      ]
    },
  ]
  const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })
  
  const router = createRouter()
  
  export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
  }
  
  export default router
  
  //vue-router相同路径跳转报错，重写replace方法
  const originalReplace = Router.prototype.replace
  Router.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err)
  }
  
  //vue-router3.0以上的
// 如果你的改了push还是没有生效，可以考虑改replace方法 
// 修改路由replace方法,阻止重复点击报错
  const originalPush = Router.prototype.push
  Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
  }
  